package game.controller
{
	import game.constants.ApplicationNotification;
	import game.model.building.BuildingProxy;
	import game.model.building.vo.BuildingVO;
	import game.model.player.PlayerProxy;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Thot
	 */
	
	public class UpdateBuildingsCommand extends SimpleCommand
	{
		override public function execute( notification:INotification ):void
		{
			var playerProxy:PlayerProxy = facade.retrieveProxy( PlayerProxy.NAME ) as PlayerProxy;
			var buildProxy:BuildingProxy = facade.retrieveProxy( BuildingProxy.NAME ) as BuildingProxy;
			var list:Vector.<BuildingVO> = buildProxy.getBuildings();
			var vo:BuildingVO;
			var i:int = list.length;
			
			while ( --i > -1 )
			{
				vo = list[i];
				
				playerProxy.currentPlayer.gold += vo.prodGold;
				playerProxy.currentPlayer.mana += vo.prodMana;
				
				if ( vo.hasReachedNextLevel() )
				{
					sendNotification( ApplicationNotification.INCREASE_BUILDING, { "name":vo.name, "id": vo.id } );
				}
			}
		}
	}

}